Imports System.Data.SqlClient
Imports System.Drawing
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Repository

'--- Created Date On : 18-Nov-2010 (Gyana)

Public Class frmRptVendorListing
    Dim mblnChanged As Boolean
    Private Sub frmRptVendorListing_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call SetImageControl(Me)
        Call GetAccessPermission(Me, "frmRptVendorListing")
        Call PopulateData()
    End Sub

    Private Sub PopulateData()
        Dim strQuery As String
        Dim dsTemp As DataSet
        Try
            strQuery = "Select VendorId [record_id],Convert(Bit,0) [Select],VendorName [Name],Address1,Address2,Town,Parish,Country" & _
                        " ,ZipCode,Phone1 [WorkPhone],Phone2 [HomePhone],MobileNo,FaxNo,Email,Website" & _
                        " From vwVendorDetails"
            dsTemp = FillDataSet(strQuery)
            With grdRecords
                .BeginUpdate()
                .DataSource = dsTemp.Tables(0)
                .EndUpdate()
            End With
            With gdvRecords
                .Columns("record_id").Visible = False
                .Columns("record_id").OptionsColumn.ShowInCustomizationForm = False
                .Columns("Select").Width = 50
                .Columns("Name").Width = 125
                .Columns("Name").OptionsColumn.AllowEdit = False
                .Columns("Address1").Width = 150
                .Columns("Address1").OptionsColumn.AllowEdit = False
                .Columns("Address2").Width = 150
                .Columns("Address2").OptionsColumn.AllowEdit = False
                .Columns("Town").Width = 100
                .Columns("Town").OptionsColumn.AllowEdit = False
                .Columns("Parish").Width = 100
                .Columns("Parish").OptionsColumn.AllowEdit = False
                .Columns("Country").Width = 100
                .Columns("Country").OptionsColumn.AllowEdit = False
                .Columns("WorkPhone").Width = 100
                .Columns("WorkPhone").OptionsColumn.AllowEdit = False
                .Columns("HomePhone").Width = 100
                .Columns("HomePhone").OptionsColumn.AllowEdit = False
                .Columns("ZipCode").Width = 100
                .Columns("ZipCode").OptionsColumn.AllowEdit = False
                .Columns("Email").Width = 150
                .Columns("Email").OptionsColumn.AllowEdit = False
                .Columns("Website").Width = 150
                .Columns("Website").OptionsColumn.AllowEdit = False
                .Columns("FaxNo").Width = 100
                .Columns("FaxNo").OptionsColumn.AllowEdit = False
                .Columns("MobileNo").Width = 100
                .Columns("MobileNo").OptionsColumn.AllowEdit = False
                
                .Columns(2).SummaryItem.SetSummary(DevExpress.Data.SummaryItemType.Count, "Total {0} Record(s)")
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                 Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub chkSelectAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSelectAll.CheckedChanged

        If chkSelectAll.Checked = True Then
            For i As Integer = 0 To gdvRecords.RowCount - 1
                gdvRecords.SetRowCellValue(i, "Select", True)
            Next
        ElseIf chkSelectAll.Checked = False Then
            For i As Integer = 0 To gdvRecords.RowCount - 1
                gdvRecords.SetRowCellValue(i, "Select", False)
            Next
        End If
    End Sub

    Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click
        'Dim dsTemp As DataTable = grdRecords.DataSource
        Dim PatientIds As String = ""
        ' Dim dr As DataRow
        'For Each dr In dsTemp.Select("Select=True")
        '    If PatientIds = "" Then
        '        PatientIds = dr.Item("record_id")
        '    Else
        '        PatientIds = PatientIds & "," & dr.Item("record_id")
        '    End If
        'Next

        For intCtr As Integer = 0 To gdvRecords.RowCount - 1
            If gdvRecords.GetRowCellValue(intCtr, "Select") = True Then
                If PatientIds = "" Then
                    PatientIds = gdvRecords.GetRowCellValue(intCtr, "record_id")
                Else
                    PatientIds = PatientIds & "," & gdvRecords.GetRowCellValue(intCtr, "record_id")
                End If
            End If
        Next

        If PatientIds = "" Then
            MessageBox.Show("Please select vendors", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If
        Call ShowVendorListingReport(PatientIds, Me.ParentForm)
    End Sub
End Class
